﻿using AutocompleteMenuNS;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LabyCLI
{
    public class ChangeAutoComplete
    {
        Terminal frm = Terminal.Instance;

        public void SetChange(AutocompleteMenu AutocompleteMenu)
        {
            var items = new List<AutocompleteItem>();

            DirectoryInfo dirInfo = new DirectoryInfo(Environment.CurrentDirectory);

            if (dirInfo.GetDirectories().Count() != 0)
            {
                foreach (DirectoryInfo dir in dirInfo.GetDirectories())
                {
                    if (dir.Name.Contains(" "))
                    {
                        items.Add(new SnippetAutocompleteItem("\"" + dir.Name + "\"") { ImageIndex = 0 });
                    }
                    else
                    {
                        items.Add(new SnippetAutocompleteItem(dir.Name) { ImageIndex = 0 });
                    }
                }
            }
            else
            {
                //No directories were found.
            }

            if (dirInfo.GetFiles().Count() != 0)
            {
                foreach (FileInfo file in dirInfo.GetFiles())
                {
                    if (file.Name.Contains(" "))
                    {
                        items.Add(new FolderSnippet("\"" + file.Name + "\"") { ImageIndex = 1 });
                    }
                    else
                    {
                        items.Add(new FolderSnippet(file.Name) { ImageIndex = 1 });
                    }
                }
            }
            else
            {
                //No files were found.
            }

            AutocompleteMenu.SetAutocompleteItems(items);

            AutocompleteMenu.ToolTipDuration = 5000;
        }
        
        internal class FolderSnippet : AutocompleteItem
        {
            public FolderSnippet(string folder) : base(folder)
            {
                ToolTipText = folder;
            }
        }
    }
}
